<?php

header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 

require("../config.php");
include_once("functii.php");
include_once("restrictii.php");
include_once("simulare_atac.php");

if (isset($_GET['id']))
 $id = addentities($_GET['id']);
else
 $id = ""; 
 
if (isset($_GET['string']))
 $string = addentities($_GET['string']);
else
 $string = ""; 
 
if (isset($_GET['anulare']))
 $anulare = addentities($_GET['anulare']);
else
 $anulare = ""; 

/* 
if ($id == "16") {
 $variabila_motor_unitati = $planeta;
 $fisier = include_once("motor_unitati.php");
 unset($fisier, $variabila_motor_unitati);
}
*/

if($anulare != "")
	{
	   $rez_act_glob = mysql_fetch_row(mysql_query("SELECT `dest_planeta` FROM `actiuni_globale` WHERE `id` = '".$anulare."' LIMIT 1"));
	   $rez_user_dest = mysql_fetch_row(mysql_query("SELECT `user`,`nume` FROM `planete` WHERE `id` = '".$rez_act_glob[0]."' LIMIT 1"));
	   mutare_inapoi_trupe_ofensiva($planeta, $rez_act_glob[0], 'imbina');
	 if(strlen($anulare)==32)
	   mysql_query("DELETE FROM `actiuni_globale` WHERE `id` = '".$anulare."' LIMIT 1");
	   $subiect = "Atac anulat!";
	   $mesaj = "Jucatorul ".$user." a renuntat la atacul lansat impotriva planetei tale.";
	   $id_unic = md5(time().$rez_user_dest[0]);
	   mysql_query("INSERT INTO mesaje (id, subiect, mesaj, exp, dest, timp) VALUES ('".$id_unic."', '".$subiect."', '".$mesaj."', 'Sistem', '".$rez_user_dest[0]."', NOW( ))");
         
	}

if($id != "") {
	$rez1 = mysql_fetch_array(mysql_query("SELECT * FROM `cladiri` WHERE `nume` = '".$id."' AND `planeta` = '".$planeta."'"));
	$nume_cladire = $id;
    $rez2 = mysql_fetch_array(mysql_query("SELECT * FROM c_cladiri WHERE id = '".$nume_cladire."'"));	
	$nivel_cladire = $rez1["nivel"];
	$nivel_upgrade = $nivel_cladire+1;
	$minerale = mysql_fetch_row(mysql_query("SELECT `minerale` FROM `planete` WHERE `id` = '".$planeta."'"));
    $gaz = mysql_fetch_row(mysql_query("SELECT `gaz` FROM `planete` WHERE `id` = '".$planeta."'"));
	$cost_minerale = round(formula_incrementare($rez2["cost_minerale"], $nivel_cladire, $rez2["form_inc_minerale"], ""), -1);
	$cost_gaz = round(formula_incrementare($rez2["cost_gaz"], $nivel_cladire, $rez2["form_inc_gaz"], ""), -1);
	$locuri = round(formula_incrementare($rez2["cost_populatie"], $nivel_cladire, $rez2["form_inc_populatie"], ""));
	$durata = returnare_data(round(formula_incrementare($rez2["timp_constr"], $nivel_cladire, $rez2["formula_inc_nivel"], "")), "0");
    
	echo '<div align="right">
	<a href="javascript:void(0)" onMouseUp="javascript:ascunde_element(\'fereastraDrag\');" onMouseOver="javascript:animatie_but2(\'but_inchidere\', 1,\'but_inchidere\')" onMouseOut="javascript:animatie_but2(\'but_inchidere\', 0,\'but_inchidere\')" onMouseDown="javascript:animatie_but2(\'but_inchidere\', 2,\'but_inchidere\')"><img id="but_inchidere" src="img/but_inchidere.gif" alt="optiuni_inchidere" border="0" align="absmiddle" /></a>
	</div>';
	echo '<table width="%100" border="0" cellpadding="4" cellspacing="0" class="font_2"><tr>';
	echo '<td width="70"><img src="img/bdg_'.$rez2["avatar"].'" /></td>';
	echo '<td><strong>'.$rez2["nume"].'</strong> (Nivel: '.$nivel_cladire.')</td></tr>';
	echo '<tr><td colspan="2"><p style="text-align: justify; text-indent: 20px;">'.$rez2["descriere"].'</p></td></tr>';
	echo '<tr><td colspan="2"><p>&nbsp;</p>';
	$cale = "cladiri/".$nume_cladire.".php";
	if (file_exists($cale))
     include_once($cale);
	else
	 echo "&nbsp;";
	echo '<p>&nbsp;</p></td></tr>';
		
	if ($rez2["nume"] != "Construire")
	{
	echo '<tr><td colspan="2">';
    echo '<strong>Cerinte upgradare: </strong><br>';
	echo '<img src="img/res_minerale.gif" align="absmiddle" alt="minerale" />Minerale: '.$cost_minerale.'&nbsp;';
	echo '<img src="img/res_gaz.gif" align="absmiddle" alt="gaz" />Gaz: '.$cost_gaz.'&nbsp;';
	echo '<img src="img/ico_durata.gif" align="absmiddle" alt="durata" />Durata: '.$durata.'&nbsp;';
	echo '<img src="img/res_populatie.gif" align="absmiddle" alt="durata" />Locuri: '.$locuri;
	echo '</td></tr><tr><td colspan="2">';
	$status = verificare_cladire($nume_cladire, $nivel_cladire, $planeta);
	if ($status == 1)
		{ 
		 if($rez2["cerinte"] != "0") {
		 $cerinte = explode(",",$rez2["cerinte"]);
		 $i=0; 
		 $k=0;
		 if($nume_cladire!=3)
		 while(isset($cerinte[$i]))
		 		{
				// Separa cerintele...
				 list($cladire, $nivel) = explode("@", $cerinte[$i]);
				// Vezi daca cladirea indeplineste cerintele necesare
				$nivel = $nivel_upgrade-6;
				 $verificare = mysql_num_rows(mysql_query("SELECT * FROM `cladiri` WHERE nume = '".$cladire."' AND nivel >= '".$nivel."' AND planeta = '".$planeta."'"));
				 if($verificare!=0)
				 		{
						 $k++;
						}
				 $i++;
				}
				 if($k==$i)
		 	{
	echo '<a href="javascript:void(0)" onclick="javascript:actiuni(\'0\', \'upgrade\', \''.$rez1["santier"].'\', \''.$rez2["nume"].'\');ascunde_element(\'optiuni_frame\'); returnare_planeta();" onMouseOver="javascript:animatie_but2(\'but_upgrade\', 1,\'but_upgrade\')" onMouseOut="javascript:animatie_but2(\'but_upgrade\', 0,\'but_upgrade\')"><img id="but_upgrade" src="img/but_upgrade.gif" alt="upgrade" border="0" align="absmiddle" /> Upgrade la nivelul '.$nivel_upgrade.'</a>&nbsp;';}else{echo '<img id="but_upgrade" src="img/but_upgrade.gif" alt="upgrade" border="0" align="absmiddle" />Nu se poate face upgrade'; }}else {echo '<a href="javascript:void(0)" onclick="javascript:actiuni(\'0\', \'upgrade\', \''.$rez1["santier"].'\', \''.$rez2["nume"].'\');ascunde_element(\'optiuni_frame\'); returnare_planeta();" onMouseOver="javascript:animatie_but2(\'but_upgrade\', 1,\'but_upgrade\')" onMouseOut="javascript:animatie_but2(\'but_upgrade\', 0,\'but_upgrade\')"><img id="but_upgrade" src="img/but_upgrade.gif" alt="upgrade" border="0" align="absmiddle" /> Upgrade la nivelul '.$nivel_upgrade.'</a>&nbsp;';}
	}
	 else
	echo '<img src="img/but_upgrade.gif" alt="upgrade" border="0" align="absmiddle" />'.$status.'&nbsp;';
	if ($rez1["nume"] != '1') {
	echo '<a href="javascript:void(0)" onclick="javascript:actiuni(\'0\', \'demolare\', \''.$rez1["santier"].'\', \''.$rez2["nume"].'\');ascunde_element(\'optiuni_frame\')" onMouseOver="javascript:animatie_but2(\'but_demolare\', 1,\'but_demolare\')" onMouseOut="javascript:animatie_but2(\'but_demolare\', 0,\'but_demolare\');"><img id="but_demolare" src="img/but_demolare.gif" alt="demolare" border="0" align="absmiddle" />';
    if ($nivel_cladire > 1) 
	 echo 'Demolare un nivel';
	else
	 echo 'Demolare totala';
	echo '</a>';
	}
	echo '</td></tr>';
 }
}

mysql_close($db);
 
?>